package sunsun.xiaoli.jiarebang.utils;

import com.itboye.pondteam.presenter.UserPresenter;
import com.itboye.pondteam.utils.Const;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Administrator (IntelliJ IDEA) on 2018/7/5.
 *
 * @description: xiaolizhineng_android
 */
public class ComparePondFilterVersion {
    public static boolean isTrue(String oldVersion) {
        String str = oldVersion;
        String pattern = "^[A-Za-z]+[0-9]+(\\.[0-9]+[A-Za-z]{1,3})?$";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(str);
//        if (m.matches()) {
//            float ver = Float.parseFloat(oldVersion.substring(1, oldVersion.length() - 1).replace(".", ""));
//            if (ver < 14) {
//                return true;
//            }
//        }
        return m.matches();
    }

    public static boolean isTrue2(String oldVersion) {
        String str = oldVersion;
        String pattern = "^[0-9]+(\\.[0-9]+[A-Za-z]{1,3})?$";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(str);
//        if (m.matches()) {
//            float ver = Float.parseFloat(oldVersion.substring(1, oldVersion.length() - 1).replace(".", ""));
//            if (ver < 14) {
//                return true;
//            }
//        }
        return m.matches();
    }

    public static void changeHostOrPort(String oldVersion, UserPresenter userPresenter, TcpUtil tcpUtil, boolean isWithLetter) {
//        float ver = 0;
//        if (isWithLetter) {
//            ver = Float.parseFloat(oldVersion.substring(1, oldVersion.length() - 1).replace(".", ""));
//        } else {
//            ver = Float.parseFloat(oldVersion.substring(1, oldVersion.length()).replace(".", ""));
//        }
//        if (ver >= 14) {
//            if (userPresenter != null) {
//                userPresenter.setBaseUrl(Const.pondlink_wrapUrl);
//            }
//            if (tcpUtil != null) {

        userPresenter.setBaseUrl(Const.pondlink_wrapUrl);
        if (tcpUtil != null) {
            tcpUtil.HOST = Const.pondlink_wrapUrl;
            tcpUtil.PORT = Const.PONDLINK_PORT;
        }
//            }
//        } else {
//        }
    }

    public static float subVersion(String oldVersion, boolean isWithLetter) {
        float ver = 0;
        if (isWithLetter) {
            ver = Float.parseFloat(oldVersion.substring(1, oldVersion.length() - 1));
        } else {
            ver = Float.parseFloat(oldVersion.substring(1, oldVersion.length()));
        }
        return ver;
    }
}
